// 用于Pc依赖注入v5的外置文件
const seeyonBuild = require('../../seeyonBuild.json');
const PR = seeyonBuild.pathResolve;
const staticSuffix = PR.staticSuffix;
const staticPath = PR.staticPath;
var smpOption = {
  js: [],
  css: []
};

var moduleDependency = {
  supervise: {
    before: {
      js: []
    },
    js: [
      `${staticPath}/ajaxStub.js${staticSuffix}`,
      // `${staticPath}/portal/pagelayout/front_common.js${staticSuffix}`,
      `${staticPath}/common/js/ui/calendar/calendar-language.js${staticSuffix}`
      // `${staticPath}/apps_res/collaboration/js/CollaborationApi.js${staticSuffix}`,
      // `${staticPath}/common/workflow/workflowDesigner_api.js${staticSuffix}`
    ],
    css: []
  },
  todoList: {
    before: {
      js: []
    },
    js: [
      // `${staticPath}/common/coll-min.js${staticSuffix}`
    ],
    css: [`${staticPath}/skin/xicon/xicon-min.css${staticSuffix}`]
  },
  finishList: {
    js: [`${staticPath}/common/page-guide/index.js${staticSuffix}`]
  }
};

function V5Plugin() {
  // 本地启动，自动添加一些外部依赖
  smpOption.css.push(`${staticPath}/skin/dist/fonts/syIconfont.css${staticSuffix}`);
  smpOption.css.push(
    `${staticPath}/skin/dist/min/skinComponents-defaultTheme-min.css${staticSuffix}`
  );
  smpOption.css.push(`${staticPath}/common/all-min.css${staticSuffix}`);
  smpOption.css.push(`${staticPath}/skin/xicon/xicon-min.css${staticSuffix}`);

  smpOption.js.push(`${staticPath}/common/all-min.js${staticSuffix}`);
  smpOption.js.push(`${staticPath}/apps_res/collaboration/js/batch.js${staticSuffix}`);
  smpOption.js.push(`${staticPath}/common/coll-min.js${staticSuffix}`);
  smpOption.js.push(`${staticPath}/common/colList-min.js${staticSuffix}`);
  smpOption.js.push(`${staticPath}/common/workflow/workflowDesigner_ajax.js${staticSuffix}`);
  smpOption.js.push(`${staticPath}/common/workflow/workflowDesigner_api-min.js${staticSuffix}`);
  smpOption.js.push(`${staticPath}/apps_res/collaboration/js/CollaborationApi.js${staticSuffix}`);
  smpOption.js.push(`${staticPath}/common/cap-dynamic-front/load.js${staticSuffix}`);

  this.v5options = smpOption;
  this.moduleDependency = moduleDependency;
}

V5Plugin.prototype.apply = function (compiler) {
  var v5options = this.v5options;
  var moduleDependency = this.moduleDependency;
  compiler.plugin('compilation', function (compilation) {
    compilation.plugin('html-webpack-plugin-before-html-generation', function (htmlPluginData) {
      htmlPluginData.plugin.options.v5options = v5options;
      htmlPluginData.plugin.options.moduleDependency = moduleDependency;
    });
  });
};

module.exports = V5Plugin;
